14 / 16

What is a Linked List? How does it differ from an Array?

Linked List vs Array

javascript
  1. 1

    Array: contiguous memory and O(1) indexed access.

  2. 2

    Linked List: non-contiguous nodes connected through references.

  3. 3

    Array insertion/deletion in the middle is generally O(n).

  4. 4

    Linked List insertion/deletion can be O(1) when the required position or node reference is already available.

  5. 5

    Linked Lists have additional memory overhead for node references.

  6. 6

    Arrays generally provide better cache locality.

Difficulty: 1/10

Follow-up Questions

  • Why is linked-list access O(n)?
  • When would you choose a linked list over an array?
  • What are the memory overheads of linked lists?